package com.caow.composebase.utils

import android.graphics.drawable.Drawable
import com.caow.composebase.GlobalConfig

/**
 * @Author caow
 * 2023/4/6
 */
object AppUtils {

    /**
     * 获取应用Icon
     */
    fun getAppIcon(): Drawable {
        val packageName = GlobalConfig.app.packageName
        val pm = GlobalConfig.app.packageManager
        return pm.getApplicationIcon(packageName)
    }

    /**
     * 获取应用名称
     */
    fun getAppName(): String {
        val packageName = GlobalConfig.app.packageName
        val pm = GlobalConfig.app.packageManager
        return pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)).toString()
    }

    /**
     * 获取App路径
     */
    fun getAppPath(): String {
        val packageName = GlobalConfig.app.packageName
        val pm = GlobalConfig.app.packageManager
        val pi = pm.getPackageInfo(packageName, 0)
        return pi.applicationInfo.sourceDir
    }

    /**
     * 获取App版本号
     */
    fun getAppVersionCode(): Int {
        val packageName = GlobalConfig.app.packageName
        val pm = GlobalConfig.app.packageManager
        val pi = pm.getPackageInfo(packageName, 0)
        return pi.versionCode
    }

    /**
     * 获取App版本名称
     */
    fun getAppVersionName(): String {
        val packageName = GlobalConfig.app.packageName
        val pm = GlobalConfig.app.packageManager
        val pi = pm.getPackageInfo(packageName, 0)
        return pi.versionName
    }

    /**
     * 获取App包名
     */
    fun getAppPackageName(): String {
        return GlobalConfig.app.packageName
    }

}